package com.trdcore.zyzkt.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trdcore.zyzkt.model.activity.CouponInfo;
import com.trdcore.zyzkt.model.activity.CouponUse;
import com.trdcore.zyzkt.resp.ResultData;
import com.trdcore.zyzkt.service.CouponInfoService;
import com.trdcore.zyzkt.vo.activity.CouponUseQueryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 优惠券信息 前端控制器
 * </p>
 *
 * @author Luffy
 * @since 2024-03-19
 */
@RestController
@RequestMapping("/admin/activity/couponInfo")
@Tag(name = "优惠券信息")
public class CouponInfoController {

    @Autowired
    private CouponInfoService couponInfoService;

    @Operation(summary = "获取分页列表",description ="获取分页列表" )
    @GetMapping("{page}/{limit}")
    public ResultData index(
            @Parameter(name = "page", description = "当前页码", required = true)
            @PathVariable("page") Long page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Long limit) {
        Page<CouponInfo> pageParam = new Page<>(page, limit);
        IPage<CouponInfo> pageModel = couponInfoService.page(pageParam);
        return ResultData.success(pageModel);
    }

    @Operation(summary = "获取优惠券",description = "获取优惠券")
    @GetMapping("get/{id}")
    public ResultData get(@PathVariable("id") String id) {
        CouponInfo couponInfo = couponInfoService.getById(id);
        return ResultData.success(couponInfo);
    }

    @Operation(summary = "新增优惠券",description = "新增优惠券")
    @PostMapping("save")
    public ResultData save(@RequestBody CouponInfo couponInfo) {
        return ResultData.success(couponInfoService.save(couponInfo));
    }

    @Operation(summary = "修改优惠券",description = "修改优惠券")
    @PutMapping("update")
    public ResultData updateById(@RequestBody CouponInfo couponInfo) {
        return ResultData.success( couponInfoService.updateById(couponInfo));
    }

    @Operation(summary = "删除优惠券",description = "删除优惠券")
    @DeleteMapping("remove/{id}")
    public ResultData remove(@PathVariable("id") String id) {
        return ResultData.success(couponInfoService.removeById(id));
    }

    @Operation(summary="根据id列表删除优惠券",description = "根据id列表删除优惠券")
    @DeleteMapping("batchRemove")
    public ResultData batchRemove(@RequestBody List<String> idList){
        return ResultData.success(couponInfoService.removeByIds(idList));
    }

    @Operation(summary = "获取优惠券使用详情",description = "获取优惠券使用详情")
    @GetMapping("couponUse/{page}/{limit}")
    public ResultData index(
            @Parameter(name = "page", description = "当前页码", required = true)
            @PathVariable("page") Long page,

            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Long limit,
            @Parameter(name = "couponUseVo", description = "查询对象", required = false)
            CouponUseQueryVo couponUseQueryVo) {
        Page<CouponUse> pageParam = new Page<>(page, limit);
        couponInfoService.selectCouponUsePage(pageParam, couponUseQueryVo);
//        IPage<CouponUse> pageModel =
        return ResultData.success(null);
    }
}

